<style lang="scss">
	page {
		background: #FFFFFF;
		overflow-x: hidden;

		.all {
			width: 750upx;

			.logo {
				width: 344upx;
				height: 344upx;
				margin-top: 26upx;
				margin-left: 203upx;
			}

			.anniu {
				width: 670upx;
				height: 96upx;
				background: #A02731;
				border-radius: 48upx;
				margin-top: 58upx;
				margin-left: 40upx;
				text-align: center;
				line-height: 96upx;
				font-size: 34upx;
				color: #FFFFFF;
			}

			.anniu_new {
				width: 670upx;
				height: 96upx;
				background: #C7CFCB;
				border-radius: 48upx;
				margin-top: 58upx;
				margin-left: 40upx;
				text-align: center;
				line-height: 96upx;
				font-size: 34upx;
				color: #FFFFFF;
			}

			.agreement {
				display: flex;
				margin-top: 40upx;
				margin-left: 60upx;

				.agreement_image {
					width: 30upx;
					height: 30upx;
					margin-top: 3upx;
				}

				.agreement_text {
					margin-left: 30upx;
					height: 36upx;
					font-size: 26upx;
					font-weight: 400;
					color: #999999;
					line-height: 36upx;
				}
			}

			.all_bj {
				width: 520upx;
				height: 388upx;
				position: fixed;
				bottom: 0;
				margin-left: 115upx;
			}

			.new {
				width: 700upx;
				padding: 0;
				margin-left: 25upx;
			}

			.new_box {
				width: 700upx;
				padding: 14upx 0;
				border-bottom: 1upx solid #DDDDDD;
				display: flex;
			}

			.new_box_image {
				width: 52upx;
				height: 54upx;
			}

			.new_box_input {
				margin-left: 8upx;
				margin-top: 8upx;
				width: 478upx;
				height: 40upx;
				font-size: 28upx;
				font-weight: 400;
				color: #222222;
				line-height: 40upx;
			}

			.new_box_text {
				width: 140upx;
				height: 40upx;
				font-size: 28upx;
				font-weight: 400;
				color: #6B542A;
				line-height: 40upx;
			}

			.zhuche {
				text-align: center;
				font-size: 28upx;
				color: #007AFF;
				padding: 20upx 0;
				width: 100%;
			}
		}
	}
</style>
<template>
	<view class="all">
		<image class="logo" src="../../../static/logo.png"></image>
		<view class="new">
			<view class="new_box" style="margin-top: 20upx;">
				<input placeholder="请输入账号" @input="account_input" class="new_box_input" />
			</view>
			<view class="new_box" style="margin-top: 20upx;">
				<input placeholder="请输入手机号" @input="phone_input" type="number" maxlength="11" class="new_box_input" />
				<view class="new_box_text" v-if="showText_now==true" @click.stop="code_tap">获取验证码</view>
				<view v-if="showText_now!=true" class="new_box_text" style="text-align: right;">{{second_now}}s</view>
			</view>
			<view class="new_box" style="margin-top: 20upx;">
				<input placeholder="请输入验证码" @input="code_input" type="number" maxlength="6" class="new_box_input" />
			</view>
			<view class="new_box" style="margin-top: 20upx;">
				<input placeholder="请输入登录密码" @input="password_input"  class="new_box_input" />
			</view>
			<view class="new_box" style="margin-top: 20upx;">
				<input placeholder="请输入交易密码" @input="pay_password_input"  class="new_box_input" />
			</view>
			<view class="new_box" style="margin-top: 20upx;">
				<input placeholder="请输入邀请码" @input="token_input" :value="token"  class="new_box_input" />
			</view>
		</view>
		<button class="anniu" @tap="getUserInfo">注册</button>
		<view class="zhuche" @click="disembark">已有账号，去登陆</view>
		<view class="zhuche" @click="Forgot_tap">忘了密码？</view>
		<view class="agreement">
			<image class="agreement_image" @click="dianji"
				:src="is_dianji==0?'../../../static/48.png':'../../../static/67.png'"></image>
			<view class="agreement_text" @click="dianji"> 我已同意 <text style="color: #393E42;"
					@click.stop="Service_tap">《用户协议》</text> 和 <text style="color: #393E42;"
					@click.stop="Privacy_tap">《隐私协议》</text> </view>
		</view>
	</view>
</template>
<script>
	import url_config from '../../../common/config.js'
    const app = getApp()
	export default {
		data() {
			return {
				is_dianji: 0,
				token: '',
				phone: '',
				code: '',
				showText_now: true,
				is_key: '',
				second_now: 60,
				password_data: '',
				password: '',
				account:'',
				invite: '',
				token:'',
				codes:'',
				codess:'',
				pay_password:'',
			}
		},
		onLoad(num) {
			if( num.scene != null && num.scene != undefined ) {
				this.token = num.scene
			}
			console.log('num',num)
		},
		onShow() {
			// this.login_tap()
		},
		methods: {
			login_tap() {
				var that = this
				that.login_api()
				// uni.login({
				// 	provider: 'weixin',
				// 	success: (loginRes) => {
				// 		that.codess = loginRes.code
				// 		// that.loginTest(that.code)
				// 	}
				// })
			},
			token_input(num) {
				this.token = num.detail.value
			},
			Forgot_tap() {
				uni.navigateTo({
					url: '../Forgot_tap/Forgot_tap'
				})
			},
			disembark() {
				uni.redirectTo({
					url:'/pages/login/disembark/disembark'
				})
				// uni.navigateBack({
				// 	delta: 1
				// })
			},
			dianji() {
				if (this.is_dianji == 0) {
					this.is_dianji = 1
				} else {
					this.is_dianji = 0
				}
			},
			//获取验证码
			code_tap() {
				var reg = /^((13\d)|(14[5,7,9])|(15[0-3,5-9])|(166)|(17[0,1,2,3,5,6,7,8,9,])|(18[0-9])|(19[8,9]))\d{8}/;
				this.showText_now = false
				this.acquire_api(this.phone) //获取验证码
				var interval = setInterval(() => {
					let times = --this.second_now
					this.second_now = times < 10 ? '0' + times : times //小于10秒补 0
				}, 1000)
				setTimeout(() => {
					clearInterval(interval)
					this.second_now = 60
					this.showText_now = true
				}, 60000)
			},
			acquire_api(phone) {
				var that = this
				uni.request({
					url: url_config.Url + 'sms/sms', //仅为示例，并非真实接口地址。
					data: {
						phone: phone,
					},
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: (res) => {}
				});
				// that.$request(that.$Api.sms, {
				// 	phone:phone,
				// },"POST").then(res => {
				// })
			},
			phone_input(num) {
				this.phone = num.detail.value
				// console.log('this.phone', this.phone,num)
			},
			code_input(num) {
				this.code = num.detail.value
			},
			account_input(num) {
				this.account = num.detail.value
			},
			pay_password_input(num) {
				this.pay_password = num.detail.value
			},
			password_input(num) {
				this.password = num.detail.value
			},
			Service_tap() {
				uni.navigateTo({
					url: '/pages/about/about'
				})
			},
			Privacy_tap() {
				uni.navigateTo({
					url: '/pages/guide/guide'
				})
			},
			getUserInfo() {
				var that = this
				if (that.phone.length == 11) {
					console.log('0', that.code)
					if (that.code != '') {
						console.log('1')
						if (that.is_dianji == 1) {
							if( that.password != '' ) {
								if( that.pay_password != '' ) {
									if( that.account != '' ) {
										that.login_api()
									}else{
										uni.showToast({
											title: '请输入账号',
											duration: 2000,
											icon: 'none'
										});
									}
								}else{
									uni.showToast({
										title: '请输入交易密码',
										duration: 2000,
										icon: 'none'
									});
								}
							}else{
								uni.showToast({
									title: '请输入密码',
									duration: 2000,
									icon: 'none'
								});
							}
						} else {
							uni.showToast({
								title: '请勾选协议',
								duration: 2000,
								icon: 'none'
							});
						}
					} else {
						uni.showToast({
							title: '请输入验证码',
							duration: 2000,
							icon: 'none'
						});
					}
				} else {
					uni.showToast({
						title: '请输入正确手机号',
						duration: 2000,
						icon: 'none'
					});
				}
			},
			login_api(phone) {
				var that = this
				uni.request({
					url: url_config.Url + 'login/registered', //仅为示例，并非真实接口地址。
					data: {
						account:that.account,
						phone: that.phone,
						code: that.code,
						pay_password:that.pay_password,
						token: that.token,
						password:that.password,
						// codes:that.codess
					},
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: (res) => {
						if (res.data.code == 0) {
							uni.setStorageSync('access_token', res.data.data.access_token);
							uni.reLaunch({
								url: '../../index/index'
							}) 

						} else {
							// that.login_tap()
							uni.showToast({
								title: res.data.msg,
								duration: 2000,
								icon: 'none'
							});
						}
					}
				});
			},
		}
	}
</script>
